var that,
  api = new(require('../../utils/api.js')),
  headimg = api.getimgurl(),
  staticimg = api.getstaticimgurl(),
  QQMapWX = require('../../utils/qqmap-wx-jssdk.js'),
qqmapsdk,
  util = new(require('../../utils/util.js'));
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    keeperswitchindex:0,
    keeperlist:[],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    that = this;
    that.getkeeperlist(that.data.keeperswitchindex)
  },
  getkeeperlist(type){
    
    wx.showLoading({
      title: '加载中',
    })
    api.keeper_getmylist(type,res=>{
      wx.hideLoading()
      if(res.data.issuccess==1){
        let newlist = res.data.list,{keeperlist} = that.data;
        newlist.forEach((x,i)=>{
          newlist[i]['date'] = util.formatTimenosecend(new Date(newlist[i]['date']*1000))
        })
        keeperlist=keeperlist.length>0?keeperlist.concat(newlist):newlist
        that.setData({keeperlist})
      }else{
        util.nocancelmodal(res.data.msg)
      }
    })
  
  },

  tostore(e){
    let{name,id} = e.currentTarget.dataset;
    wx.navigateTo({
      url: '../store/store?id='+id+"&name="+name,
    })

  },
  keepswitch(e){
    let{keeperswitchindex} = this.data,{code} =e.currentTarget.dataset ;
    if(code==keeperswitchindex) return;
    that.setData({keeperswitchindex:code,keeperlist:[]},res=>{
      that.getkeeperlist(code)
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})